// pages/card/card.js
var app = getApp();
//声明弹幕数组
var barrage_style_arr = [];
// 声明单条弹幕
var barrage_style_obj = {};
// 声明弹幕下标
var arrIndex = 0;
// 声明屏幕宽度
var phoneWidth = 0;
var timers = [];
var timer;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    title: '校园宝卡',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    num: '暂未开通宝卡',
    searchcon: '搜索商家吧',
    indexEquity: '',
    lunbolist:[],
    goodlist:[],
 
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getProgramPic();
    this.getTuijianBusiness();


  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  goHot(){
   wx.navigateTo({
     url: '../../pages/hot/hot',
   })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    var token = wx.getStorageSync('token');

    app.getUserInfo(token, function (res) {
      console.log(res);
      that.setData({
        num: res.ranDomNum
      })
      console.log(res.ranDomNum)
    });

  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },




  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  // 判断登录
  login() {
    var token = wx.getStorageSync('token');
    if (token) {
      app.getUserInfo(token, function (res) {

      });
    } else {

    }
  },
  // 获取程序图片
  getProgramPic() {
    var that = this;
    app.ajaxPost('product/getProgramPic', '', function (res) {
      console.log(res.data[0].indexEquity)
      that.setData({
        indexEquity: res.data[0].indexEquity,
        lunbolist: res.data[0].lunboImg
      })
    })
  },
  // 开通宝卡
  kaitong() {
    var token = wx.getStorageSync('token');
    if (token) {
      app.getUserInfo(token, function (res) {

      });
    } else {
      app.openToast('暂未登录,请登录', 'none', 1000);
      setTimeout(function () {
        wx.switchTab({
          url: '../../pages/my/my',
        })
      }, 1000)

    }
  },
  getTuijianBusiness() {
  console.log('5454')
    var that = this;
    app.ajaxPost('product/getTuijianBusiness','', function (res) {
      console.log(res.data);
      var newGoodList = [...that.data.goodlist, ...res.data];
      console.log(newGoodList)
     
        that.setData({
          goodlist: newGoodList
        })
    })
  },
  goYyy(){
    wx.navigateTo({
      url: '../../pages/yyy/yyy',
    })
  }

})